﻿<UserControl x:Class="Microsoft.EnhancedReminders.OutlookAddIn.ChannelControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ds="clr-namespace:Microsoft.EnhancedReminders.OutlookAddIn"
    xmlns:properties="clr-namespace:Microsoft.EnhancedReminders.Properties">

    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static ds:ChannelControl.AddCommand}"
                    Executed="AddChannel" CanExecute="AddCommandCanExecute"/>

        <CommandBinding Command="{x:Static ds:ChannelControl.EditCommand}"
                    Executed="EditChannel" CanExecute="EditCommandCanExecute"/>

        <CommandBinding Command="{x:Static ds:ChannelControl.DeleteCommand}"
                    Executed="DeleteChannel" CanExecute="DeleteCommandCanExecute"/>

        <CommandBinding Command="{x:Static ds:ChannelControl.UpCommand}"
                    Executed="MoveChannelUp" CanExecute="UpCommandCanExecute"/>
                    
        <CommandBinding Command="{x:Static ds:ChannelControl.DownCommand}"
                    Executed="MoveChannelDown" CanExecute="DownCommandCanExecute"/>
    
    </UserControl.CommandBindings>

    <UserControl.Resources>
    
        <!-- Channels data object to bind to -->   
        <ObjectDataProvider x:Key="Channels" ObjectType="{x:Type ds:NotificationChannelUICollection}"/>

        <!-- Template to define the styles of a channel ListBox item. -->
        <DataTemplate x:Key="ItemTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="37"/>
                    <ColumnDefinition Width="32"/>
                    <ColumnDefinition Width="95"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <CheckBox Grid.Column="0" Margin="3,0,0,0"  VerticalAlignment="Center" IsChecked="{Binding Path=IsEnabled}" IsEnabled="{Binding Path=CheckBoxIsEnabled}"/>
                <Image Margin="0,5,0,5" Grid.Column="1" VerticalAlignment="Center" Source="{Binding Path=NotificationChannelIcon}" />
                <TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Path=NotificationChannelTypeString}" />
                <TextBlock Grid.Column="3" VerticalAlignment="Center" Text="{Binding Path=UserDefinedName}" />
            </Grid>
        </DataTemplate>

        <Style x:Key="ItemStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Height" Value="39" /> <!-- Height needs to be slightly less than 40 to display 4 items fully -->
            <Setter Property="Background" Value="WhiteSmoke" />
            <Setter Property="BorderThickness" Value="0.5" />
            <Setter Property="BorderBrush" Value="LightGray" />
        </Style>
    
        <Style x:Key="HeaderStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Height" Value="10" />
        </Style>

        <Thickness x:Key="ButtonMargin">0,0,5,0</Thickness>
        
        <Style x:Key="UpArrowStyle" TargetType="{x:Type Image}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="True" >
                    <Setter Property="Source" Value="..\images\UpArrow.png"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Source" Value="..\images\UpArrowFaded.png"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        
        <Style x:Key="DownArrowStyle" TargetType="{x:Type Image}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="True">
                    <Setter Property="Source" Value="..\images\DownArrow.png"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Source" Value="..\images\DownArrowFaded.png"/>
                </Trigger>
            </Style.Triggers>
        </Style>

    </UserControl.Resources>

    <StackPanel>
   
        <!-- Add/edit/delete/up/down buttons -->
        <DockPanel FlowDirection="LeftToRight" Height="25" Margin="0,0,0,10">
            <Button Name="addButton" Margin="{DynamicResource ButtonMargin}" Width="90" Command="{x:Static ds:ChannelControl.AddCommand}" Content="{x:Static properties:Resources.ChannelControlAddButton}"/>
            <Button Name="editButton" Margin="{DynamicResource ButtonMargin}" Width="75" Command="{x:Static ds:ChannelControl.EditCommand}" Content="{x:Static properties:Resources.ChannelControlEditButton}"/>
            <Button Name="deleteButton" Margin="{DynamicResource ButtonMargin}" Width="75" Command="{x:Static ds:ChannelControl.DeleteCommand}" Content="{x:Static properties:Resources.ChannelControlDeleteButton}"/>
            <DockPanel FlowDirection="LeftToRight" HorizontalAlignment="Right">
                <Button Name="upButton" Command="{x:Static ds:ChannelControl.UpCommand}">
                    <Image Style="{StaticResource UpArrowStyle}" />
                </Button>
                <Button Name="downButton" Command="{x:Static ds:ChannelControl.DownCommand}">
                    <Image Style="{StaticResource DownArrowStyle}" />
                </Button>
            </DockPanel>
        </DockPanel>
    
        <!-- ListBox headers. -->
        <DockPanel FlowDirection="LeftToRight" VerticalAlignment="Bottom">
            <CheckBox Name="enableAll" Margin="5,0,0,0" VerticalAlignment="Center" 
                      IsChecked="{Binding Path=AllEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ds:ChannelControl}}, Mode=TwoWay}" 
                      Content="{x:Static properties:Resources.ChannelControlEnabledCheckbox}"/>
            <Label Margin="5,0,0,0" Width="125" Content="{x:Static properties:Resources.ChannelControlChannelLabel}"/>
            <Label Content="{x:Static properties:Resources.ChannelControlNameLabel}"/>
        </DockPanel>

        <!-- The channels ListBox. -->        
        <ListBox ScrollViewer.CanContentScroll="True" Height="160" Grid.Row="1" Name="channelsListBox" Background="WhiteSmoke" MouseDoubleClick="channelsListBox_MouseDoubleClick"
            ItemsSource="{Binding Source={StaticResource Channels}}" 		
            IsSynchronizedWithCurrentItem="true"
            ItemContainerStyle="{StaticResource ItemStyle}"
            ItemTemplate="{StaticResource ItemTemplate}">
        </ListBox>        

    </StackPanel>
    
</UserControl>
